import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class AlertPage extends StatefulWidget {
  const AlertPage({Key? key}) : super(key: key);

  @override
  _AlertPageState createState() => _AlertPageState();
}

class _AlertPageState extends State<AlertPage> {
  FToast? fToast;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    fToast = FToast();
    fToast?.init(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Alert'),
      ),
      body: Flex(
        direction: Axis.vertical,
        children: [
          GestureDetector(
            child: Container(
              alignment: Alignment.center,
              width: 100,
              height: 100,
              padding: EdgeInsets.all(10),
              margin: EdgeInsets.all(10),
              color: Colors.pink,
              child: Text('Toast'),
            ),
            onTap: () => {this.showToast('hello world')},
          ),
          ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(10)),
            child: GestureDetector(
              child: Container(
                alignment: Alignment.center,
                width: 100,
                height: 100,
                color: Colors.pink,
                child: Text('Custom Toast'),
              ),
              onTap: () => {this.showCustomToast('hello world')},
            ),
          ),
          GestureDetector(
            child: Container(
              alignment: Alignment.center,
              width: 100,
              height: 100,
              margin: EdgeInsets.all(10),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                color: Colors.orange,
              ),
              child: Text('Alert'),
            ),
            onTap: ()=>{this.alert()},
          )
        ],
      ),
    );
  }

  void showToast(title) {
    Fluttertoast.showToast(
        msg: "This is Center Short Toast",
        toastLength: Toast.LENGTH_LONG,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Color(0xff123456),
        textColor: Colors.white,
        fontSize: 16.0);
  }

  void showCustomToast(title) {
    Widget toast = Container(
      padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(25.0),
        color: Color(0xff142133),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(
            Icons.check,
            color: Colors.white,
          ),
          SizedBox(
            width: 12.0,
          ),
          Text(
            "This is a Custom Toast",
            style: TextStyle(color: Colors.white),
          ),
        ],
      ),
    );

    fToast?.showToast(
      child: toast,
      gravity: ToastGravity.CENTER,
      toastDuration: Duration(seconds: 2),
    );
  }

  void alert(){
    print('alert');
  }
}
